package com.hengpeng.itfints.service.links.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.hengpeng.common.persist.entity.AbstractEntity.BoolValue;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.common.persist.query.Projections;
import com.hengpeng.itfinbase.persist.Links;
import com.hengpeng.itfinbase.persist.Links.LinkType;
import com.hengpeng.itfints.service.BaseService;
import com.hengpeng.itfints.service.links.LinksService;

/**
 * <pre>
 * 友情链接服务层
 * </pre>
 * @author wangtongbin
 * @version 1.0, 2012-1-7
 */
@Service
public class LinksServiceImpl extends BaseService implements LinksService
{

	@Override
	public List<Object> findLinksByType(LinkType type, String... linksField)
	{
		DynamicQuery query = new DynamicQuery(Links.class, "links");
		query.eq("isPass", BoolValue.YES);
		query.eq("links.type", type);
		if (linksField.length != 0 && linksField != null && !linksField.equals(""))
		{
			for (String field : linksField)
			{
				query.addProjection(Projections.property("links." + field));
			}
		}
		query.asc("links.sort");
		return persistService.findObject(null, query);
	}

}
